package com.ganbo.ms.nio;


import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author ganbo
 * @date 2022/11/26 20:59
 */
public class IOServer {

    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(8000);

        new Thread(() -> {
            try {
                Socket accept = serverSocket.accept();

                new Thread(() -> {
                    try {
                        InputStream inputStream = accept.getInputStream();
                        int len;
                        byte[] data = new byte[1024];
                        while ((len = inputStream.read(data)) != -1) {
                            System.out.println(new String(data, 0, len));
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }).start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }).start();
    }
}
